home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
3_0
/
OIC_1
/
OIC_SOUR
/
OBJECT.C
< prev
next >
Wrap
Text File
|
1989-03-05
|
3KB
|
178 lines
/*
* Object - the root class, inherited eventually by all classes.
*
* Copyright ⌐ John Wainwright 1988
*
* Supers : None.
*
* Class Vars : None
*
* Class Methods : None
*
* Methods :
*
* new - dummy new.
* className - returns class name String
*/
#include <stdio.h>
#include "oic.h"
#include "generics.h"
class Object; /* root Object class */
/* -------------------- Object Instance methods ---------------------------- */
method object
_new(self)
object self;
{
return self;
}
method object
_className(self)
object self;
{
return New(String, ClassOf(self)->c_name);
}
method void
_dispose(self)
object self;
{
*self = NULL; /* make it an invalid object */
free(self);
}
method object
_print(self)
object self;
{
object replist = repList(self);
print(replist);
deepDispose(replist);
}
method object
_repList(self)
object self;
{
register object p;
register int i, l;
object replist;
char buf[100];
replist = New(Replist, "<", ">", " ");
sprintf(buf, "%s:", ClassNameOf(self));
append(replist, New(String, buf));
l = ClassOf(self)->c_allocz / sizeof(object);
for (p = self + 1, i = 1; i < l; i++, p++)
if (IsObj(*p))
append(replist, repList(*p));
else
{
sprintf(buf, "%8.8lx", *p);
append(replist, New(String, buf));
}
return replist;
}
method object
_cantDo(self, dummy, ap)
object self;
char *dummy;
struct
{
GenericTable *gen;
char *args;
} *ap;
{
gprintf(error, "** No \"%s\" method for %s\n", GenericName(ap->gen), ClassNameOf(self));
return END;
}
method void
_forAll(self, dummy, ap)
object self;
char *dummy;
register struct
{
void (*f)();
double a1, a2, a3, a4, a5;
} *ap;
{
object seq, item;
for (seq = sequence(self); item = next(seq); )
(*ap->f)(item, ap->a1, ap->a2, ap->a3, ap->a4, ap->a5);
}
method void
_forAllGen(self, dummy, ap)
object self;
char *dummy;
register struct
{
GenericTable *gen;
char *args;
} *ap;
{
object seq, item;
for (seq = sequence(self); item = next(seq); )
ApplyGeneric(ap->gen, item, ap->args);
}
method object
_allInstances()
{
return New(List, END);
}
method object
_deepInstances()
{
return New(List, END);
}
method int
_equal(self, ivs, other)
object self;
char *ivs;
object *other;
{
return (ClassOf(self) == ClassOf(*other) &&
ClassOf(self)->c_allocz == ClassOf(*other)->c_allocz &&
strncmp(self, *other, ClassOf(self)->c_allocz));
}
/* ------------------- Init the Object class ------------------------------- */
/*
* note that the Object has already been made in the ONLY function
* that should call this: InitRootClasses in obj.c
*/
InitObject()
{
AddMethods(Object,
allInstancesGeneric, _allInstances,
cantDoGeneric, _cantDo,
classNameGeneric, _className,
deepDisposeGeneric, _dispose,
deepInstancesGeneric, _deepInstances,
disposeGeneric, _dispose,
equalGeneric, _equal,
forAllGeneric, _forAll,
forAllGenGeneric, _forAllGen,
mapGeneric, _forAll,
newGeneric, _new,
printGeneric, _print,
repListGeneric, _repList,
END);
}